package com.example.controller;

import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
public class StudentController {


    //添加添加学生

    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Student student){
        System.out.println(student);
        return Result.success();
    }

    //学生列表
    @GetMapping("/getStudentList")
    public Result getStudentList(){
        ArrayList<Student> list = new ArrayList<>();

        Student stu1 = new Student("张三",20);

        stu1.setAddress(new Address("贵州省","贵阳市"));

        Student stu2 = new Student("李斯特",22);
        stu2.setAddress(new Address("北京市","朝阳区"));

        list.add(stu1);
        list.add(stu2);
        return Result.success(list);
    }


    //json 格式参数  需要加 @RequestBody  注解
    @PostMapping("/jsonParam")
    public String jsonParam(@RequestBody Student student){
        System.out.println(student);
        return "OK";
    }

    //路径参数

    @GetMapping("/pathParam/{id}/{name}")
    public String pathParam(@PathVariable String id, @PathVariable String name){

        System.out.println(id);
        System.out.println(name);

        return "OK";
    }


}
